<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Customer_model extends CI_Model {
    var $title   = '';
    var $content = '';
    var $date    = '';
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_last_one_entries($username,$password)
    {
    	$this->load->database('default'); 
        $query = $this->db->get_where('tblcustomer',array('custname' => $username,'custpass'=>$password),1,0);
    	if($query->num_rows()>0){	
			foreach ($query->result() as $row)
			{
				$userkey =  $row->custid;
			} 
			return $userkey;
		} else {
			return 0;	
		}
    }        function getcustomerbyid($id)    {    	$this->load->database('default');         $query = $this->db->get_where('tblcustomer',array('custid'=>$id),1,0);    	if($query->num_rows()>0){				foreach ($query->result() as $row)			{				$userkey =  $row->custname;			} 			return $userkey;		} else {			return 0;			}    }
    
	function checkexit($username)
    {
    	$this->load->database('default'); 
        $query = $this->db->get_where('tblcustomer',array('uname' => $username),1,0);
    	if($query->num_rows()>0){	
			foreach ($query->result() as $row)
			{
				$userkey =  $row->ukey;
			} 
			return $userkey;
		} else {
			return 0;	
		}
    }
    
	function get_alluser()
    {
    	$this->load->database(); 
		$query = $this->db->get('tblcustomer');
		if ($query->num_rows() > 0)
        {
          return $query->result();
        } else {
          return array();
        } 
       
    }
	
    function deleteuser($id)
    {
    	$this->load->database('default'); 
    	$this->db->delete('tblcustomer', array('uid' => $id)); 
    }
    
    function insert_user($username,$userpass,$useraddress,$useravatar,$userphone,$usermail)
    {
       $this->load->database('tblcustomer'); 
        $data = array(                
			'custname' => $name ,                
			'custaddress' =>  date("Y-m-d H:i:s"),
        	'custpass' => $pass,
        	'uactive' => 1,
        	'custavatar' =>  $key ,
        	'custphone' =>  $type,
        	'custmail' => $avatar
        ); 
		$this->db->insert('tblcustomer', $data);    	
    }

    function update_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time(); 
        $this->db->update('tblcustomer', $this, array('id' => $_POST['id']));
    }

}